using System;
using UnityEngine;
using UnityEngine.UI;

namespace Script.UI.Panel
{
    public class AutoPanelWnd : MonoBehaviour
    {
        public ToggleGroup ToggleGroup;
        
        public void Awake()
        {
            var count = ToggleGroup.transform.childCount;
            for (int i = 0; i < count; i++)
            {
                var child = ToggleGroup.transform.GetChild(i);
                var toggle = child.GetComponent <Toggle>();
                toggle.onValueChanged.AddListener((arg0 => { OnToggleChange(toggle, arg0); }));
                if (toggle.isOn)
                {
                    OnToggleChange(toggle, true);
                }
            }
        }



        public void OnToggleChange(Toggle toggle,bool isActive)
        {
            if (isActive)
            {
                if (toggle.name == "Ontoggle")
                {
                    AutoController.Ins.SetIsStart(true);
                }
                else
                {
                    AutoController.Ins.SetIsStart(false);
                }
            }
        }
    }
}